<!doctype html>
<html class="no-js">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="description" content="">
  <meta name="keywords" content="">
  <meta name="viewport"
        content="width=device-width, initial-scale=1">
  <title>进度--发出的任务</title>

  <!-- Set render engine for 360 browser -->
  <meta name="renderer" content="webkit">

  <!-- No Baidu Siteapp-->
  <meta http-equiv="Cache-Control" content="no-siteapp"/>

  <link rel="icon" type="image/png" href="images/bee.png">

  <!-- Add to homescreen for Chrome on Android -->
  <meta name="mobile-web-app-capable" content="yes">
  <!-- <link rel="icon" sizes="192x192" href="assets/i/app-icon72x72@2x.png"> -->

  <!-- Add to homescreen for Safari on iOS -->
  <meta name="apple-mobile-web-app-capable" content="yes">
  <meta name="apple-mobile-web-app-status-bar-style" content="black">
  <meta name="apple-mobile-web-app-title" content="Amaze UI"/>
  <!-- <link rel="apple-touch-icon-precomposed" href="assets/i/app-icon72x72@2x.png"> -->

  <!-- Tile icon for Win8 (144x144 + tile color) -->
  <meta name="msapplication-TileImage" content="assets/i/app-icon72x72@2x.png">
  <meta name="msapplication-TileColor" content="#0e90d2">

  <link rel="stylesheet" href="assets/css/amazeui.min.css">
  <link rel="stylesheet" href="assets/css/app.css">
  <script src="../../routes/vue.js"></script>
</head>
<body style="background: url(images/bg1.png) no-repeat;background-size: cover; background-attachment:fixed;">
  
  <!--在这里编写你的代码-->
  <!-- 页头 -->
  <header data-am-widget="header"
  class="am-header am-header-default" style="background-color: #F6B541;">
  <div class="am-header-left am-header-nav">
    <!-- <a href="#left-link">
        <span class="am-header-nav-title">
          首页
        </span>
    
          <i class="am-header-icon am-icon-home"></i>
    </a> -->
    <ul>
      <a href="yfpage.html">
        <li style="display: flex;flex-direction: row;width: 200px;">
            <img src="images/shouye.png" alt="管理员联系方式" style="width: 150px; height: 22px;margin-top: 10px; margin-left: -10%;">
            <!-- <p style="color: #000; margin-top: 0;font-size: 16px;">小蜜蜂图片收集网</p> -->
        </li>
      </a>
    </ul>
    </div>
    
  
    <div class="am-header-right am-header-nav">
      <a href="jobfachu.html">
        <div style="display: flex;flex-direction: column;margin-left: -40px;">
          <img src="images/rw.png" alt="管理员联系方式" style="width: 30px; height: 25px;">
          <span style="color: black; font-weight: 700; font-size: 12px;margin-left: -48px; margin-top: -14px;" onclick="rw()">任务</span>
        </div>
      </a>
      <a href="personal.html">
        <div style="display: flex;flex-direction: column;margin-left: -10px;">
          <img src="images/xr.png" alt="管理员联系方式" style="width: 25px; height: 20px;">
          <span style="color: black; font-weight: 700; font-size: 12px;margin-left: -18px; margin-top: -14px;" onclick="per()">我的</span>
        </div>
      </a>
    </div>

  </header>


  <div class="am-container" style="background-color: rgba(241, 246, 249, 0.65); margin-top: 60px; 
   box-shadow: 5px 5px 5px rgba(0,0,0,0.1); 
  border-radius: 5px; ">
<script src="../../routes/vue.js"></script>
  <div class="am-g am-g-fixed" style="margin-top: 2vh;" id="cycle" v-for="(item ,i) in arr">
    <div class="am-u-sm-2 am-u-sm-offset-1" style="height: 30px; font-size:large; font-family: SimHei; font-weight: 700;">
        <label style="background-color: #fff;">任务编号：</label>
        <label style="background-color: #fff;">{{item.tasknum}}</label>
    </div>
    <div class="am-u-sm-6 am-u-end" style="height: 30px; font-size:large;">
        <label style="background-color: #fff;">收集日期：</label>
      <label style="background-color: #fff; width: 8vw;text-align: center;">{{item.begintime}}</label>
            <span style="width: 8vw;">--</span>
            <label style="background-color: #fff; width: 8vw;text-align: center;"> {{item.endtime}}</label>
    </div>
  </div>
  <div class="am-modal am-modal-confirm" id="my-confirm">
    <div class="am-modal-dialog">
      <div class="am-modal-hd">退款界面</div>
      <div class="am-modal-bd" id="1money"></div>
      <div class="am-modal-footer">
        <span class="am-modal-btn" id="publishBtn" data-am-modal-confirm>收款</span>
      </div>
    </div>
  </div>

  <div class="am-g am-g-fixed" style="margin-top: 5vh;margin-bottom: 3vh;">
    <div class="am-u-sm-5" style="height: 30px; font-size:large; font-family: SimHei; font-weight: 700;">
        图片收集进度<img src="images/xia.png" style="width: 25px;height:25px;">
        <button type="button" class="am-btn am-btn-primary am-round" id="downloadBtn" style="background-color: #75C3B6;
                    width:6vw;height:4vh;font-size: xx-small;outline: 0;" onclick="download()">全部下载</button>
    </div>
    <div class="am-u-sm-3  " style="height: 30px; font-size:large; text-align: center;">
      <button type="button" id="pre11" class="am-btn am-btn-danger am-round am-btn-warning" 
      style="background-color: #F6B541;outline: 0;border-radius: 50px;height: 40px;width: 160px;"  onclick="advance()" ></button>
  </div>
  </div>

 <!-- max-width:100%;max-height:100%;width:auto;height:auto; -->
        <!-- style="height: 126.4px;width: 230.4px;" -->
        <!-- <div style="width:500px;height:500px;display:flex;justify-content:center;align-items:center">
            <img src="2.jpg" style="width:100%;height:auto">
        </div> -->
  <ul data-am-widget="gallery" class="am-gallery am-avg-sm-3
  am-avg-md-3 am-avg-lg-4 am-gallery-default" data-am-gallery="{ pureview: true }" id="picturelist" >
  <li style="margin-bottom:20px;" v-for="(item ,i) in arrr">
    <div class="am-gallery-item" style="height: 126.4px;line-height: 126.4px; width: 230.4px; text-align: center;">
        <a>
          <img v-bind:src="item.picurl" style="max-width:100%;max-height:100%;width:auto;height:auto; vertical-align: bottom;" >
        </a>
    </div>
    <!-- <div class="am-btn-group" style="margin-left: 92px;">
      <button type="button" class="am-btn am-btn-primary am-round" style="background-color: #75C3B6;margin-top: 1vh;
      width:3vw;height:3vh;font-size: xx-small;">采用</button>
      <button type="button" class="am-btn am-btn-primary am-round" style="background-color: #F6B541;margin-top: 1vh;
      width:3vw;height:3vh;font-size: xx-small;">丢弃</button>
    </div> -->
  </li>
  </ul>
  </div>
  

<!-- 页脚 -->
<footer data-am-widget="footer"
class="am-footer am-footer-default"
 data-am-footer="{  }" style="background-color: rgba(255,255,255,0) ;">
<div class="am-footer-switch">
<span class="am-footer-ysp" data-rel="mobile"
data-am-modal="{target: '#am-switch-mode'}">
云适配版
</span>
<span class="am-footer-divider"> | </span>
<a id="godesktop" data-rel="desktop" class="am-footer-desktop" href="javascript:">
电脑版
</a>
</div>
<div class="am-footer-miscs ">

<p>由 <a href="http://www.yunshipei.com/" title="诺亚方舟"
                                      target="_blank">诺亚方舟</a>
  提供技术支持</p>
<p>CopyRight©2014  AllMobilize Inc.</p>
<p>京ICP备13033158</p>
<br>
<p>NaN团队--小蜜蜂图片收集网</p>
</div>
</footer>

<div id="am-footer-modal"
class="am-modal am-modal-no-btn am-switch-mode-m am-switch-mode-m-default">
<div class="am-modal-dialog">
<div class="am-modal-hd am-modal-footer-hd">
<a href="javascript:void(0)" data-dismiss="modal" class="am-close am-close-spin " data-am-modal-close>&times;</a>
</div>
<div class="am-modal-bd">
您正在浏览的是

<span class="am-switch-mode-owner">
  云适配
</span>

<span class="am-switch-mode-slogan">
    为您当前手机订制的移动网站。
</span>
</div>
</div>
</div>



<!--[if (gte IE 9)|!(IE)]><!-->
<!-- <script src="assets/js/jquery.min.js"></script> -->
<!--<![endif]-->
<!--[if lte IE 8 ]-->
<script src="http://libs.baidu.com/jquery/1.11.3/jquery.min.js"></script>
<script src="http://cdn.staticfile.org/modernizr/2.8.3/modernizr.js"></script>
<script src="assets/js/amazeui.ie8polyfill.min.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/jszip/3.6.0/jszip.min.js"></script>
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>
<!--[endif]-->
<script src="assets/js/amazeui.min.js"></script>
<script>
function advance() {
      var http = new XMLHttpRequest()
      http.open('POST','http://localhost/getinfor')
      http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
      http.send('tasknum=' + sessionStorage.getItem('tasknum'))
      http.onreadystatechange = function()
            {
                if(http.readyState == 4 && http.status == 200)
                {
                  var result = JSON.parse(http.responseText)
                  console.log(result)
                  $money=$('#1money')
                  $(function(){$money.empty(),$money.append('本任务已收集图片'+result['num']+'张，退款'+result['money']+'元')})
                }
            }
        console.log('hhhhjiji')
      $('#my-confirm').modal({
        relatedTarget: this,
        onConfirm: function() 
        {
            var http = new XMLHttpRequest()
            http.open('POST','http://localhost/finishtask')
            http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
            http.send('tasknum=' + sessionStorage.getItem('tasknum')+'&username='+sessionStorage.getItem('username'))
            http.onreadystatechange = function()
            {
                if(http.readyState == 4 && http.status == 200)
                {
                }
            }
            var pre=document.getElementById('pre11');
            pre.disabled=true;
            pre.innerHTML = '任务已结束'
        },
      });
    }

  function oneValues()
  {
    var result;
    var url=decodeURI(window.location.search); //获取url中"?"符后的字串  
    if(url.indexOf("?") != -1) {
        result = url.substr(url.indexOf("=")+1);
    }
    return result;
  }


  var http = new XMLHttpRequest()
  var pre=document.getElementById('pre11');
  http.open('POST','http://localhost/search')
  http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
  http.send('key=' + oneValues())
  http.onreadystatechange =  function()
  {
      if(http.readyState == 4 && http.status == 200)
      {
        console.log('search请求部分：输出responseText')
          console.log(http.responseText)
          // console.log(eval(http.responseText))
          var theNew = JSON.parse(http.responseText).a
          console.log(theNew)
          if(http.responseText.indexOf(true)+1)
          {
            console.log('输出theNew[0]')
            console.log(theNew[0])
            vm.arr.push(theNew[0])
            console.log(pre)
            var normalizeDate = vm.arr[0]['endtime'].split("-");
            console.log('sjh')
            console.log(normalizeDate)
            var day=new Date().getDate();
            var Month = new Date().getMonth() + 1;
            var year = new Date().getFullYear();
            console.log(day,Month,year)

            var status=sessionStorage.getItem('status')
            console.log(status)

            if(status=='已结束'){
              console.log('jinleme')
              console.log('结束了哈')
              console.log(pre)
              pre.disabled=true;
              pre.innerHTML = '任务已结束'
              }
            else{
              if (normalizeDate[0] < year)
                  {
                      console.log('年份到期了')
                      pre.disabled=true;
                      pre.innerHTML = '任务已结束'
                  } 
                  else if(normalizeDate[0] == year)
                  {
                    console.log('年份未到期')
                    if (normalizeDate[1] < Month) 
                    {
                      console.log('月分到期了')
                      pre.disabled=true;
                      pre.innerHTML = '任务已结束'
                    }
                    else if(normalizeDate[1] == Month)
                    {
                      console.log('月分未到期')
                      if (normalizeDate[2] < this.day) 
                      {
                        console.log('日期到期了')
                        pre.disabled=true;
                        pre.innerHTML = '任务已结束'
                      }else 
                      {
                        console.log('日期未到期')
                        pre.disabled=false;                        
                        pre.innerHTML = '<img src="images/ljt.png" style="height: 25px;width: 25px; "> 提前结束任务'
                      };
                    }
                    else{
                      pre.disabled=false;                        
                      pre.innerHTML = '<img src="images/ljt.png" style="height: 25px;width: 25px; "> 提前结束任务'
                    }
                  }
                  else{
                    pre.disabled=false;                        
                    pre.innerHTML = '<img src="images/ljt.png" style="height: 25px;width: 25px; "> 提前结束任务'
                  }
            }
          }
        }
  }

          var vm = new Vue({
      el: '#cycle',
      data: {
        arr:[]
      },
      methods: {
          details: function(a) {
            console.log(a)
            vm.arr.push(a)
            console.log(vm.arr.length)
          }
      }
  })
</script>

<script>
  $none=$('.none');
  var vmm = new Vue({
        el: '#picturelist',
        data: {
          arrr:[]
        },
        methods: {
            details: function(b) {
              vmm.arrr.push(b)
            },  
        }
    })
  
  var tasknum = window.sessionStorage.getItem('tasknum')

  function downloadFile(url, name) {
    let a = document.createElement("a");
    a.href = url;
    a.download = name;
    a.click();
  }

  async function download(){
    const http = new XMLHttpRequest()
    var result = []
    var imgs = []
    http.open('POST','http://localhost/download')
    http.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    http.send("tasknum="+tasknum)
    http.onreadystatechange = async function()
    {
      if(http.readyState == 4 && http.status == 200)
      {
        result = JSON.parse(http.responseText)
        if(result != []){
          for(var i=0;i<result.length;i++){
            imgs.push(result[i]['picurl'])
          }
          console.log(imgs)
          var zip = new JSZip();
          for (let url of imgs) {
            let fileName = url.split("/").reverse()[0];
            let { data } = await axios({
              method: "get",
              url,
              responseType: "blob",
            });
            zip.file(fileName, data);
          }
          zip.generateAsync({ type: "blob" }).then(function (content) {
            let url = window.URL.createObjectURL(content);
            downloadFile(url, "images");
          });
        }
      }
    }
  }

    const xhr=new XMLHttpRequest();
        xhr.open('POST','http://localhost/processfachu');
        xhr.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
        xhr.send('tasknum='+tasknum);
        console.log('下面是任务编号')
        console.log(tasknum)
        
        // const username=window.sessionStorage.getItem('username');
        xhr.onreadystatechange=function(){
            // 判断
            if(xhr.readyState == 4 && xhr.status == 200)    
            {
                    // 处理服务端返回的结果
                    console.log('下面是xhr.responseText')
                    console.log(xhr.responseText)
                    var theNeww = JSON.parse(xhr.responseText).b
                    console.log('下面是theNeww')
                    console.log(theNeww)
                    if(xhr.responseText.indexOf(true)+1)
                    {
                      console.log(vmm.arrr)
                      vmm.arrr = []
                      console.log('0.输出vmm.arrr')
                      console.log(vmm.arrr)
                      var n = theNeww.length
                      for(var i = 0;i<n;i++)
                      {
                        vmm.details(theNeww[i])
                      }

                      console.log('theNeww的长度')
                      console.log(theNeww.length)
                      console.log('1.输出vmm.arrr')
                      console.log(vmm.arrr)
                    }                                      
                  }
              }

function yfpage(){
    window.location.href='./yfpage.html'
  } 
function rw(){
    window.location.href='./jobfachu.html'
  }             

</script>
</body>
</html>